package com.example.leaderapplication.Adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.leaderapplication.R;
import com.example.leaderapplication.Utils.ToastUtil;
import com.example.leaderapplication.View.Activity.ChangePasswordActivity;

import java.util.List;

public class MyItemAdapter extends RecyclerView.Adapter<MyItemAdapter.ViewHolder> {

    private Context context;
    private List<String> mDate;

    public MyItemAdapter(Context context, List<String> mDate) {
        this.context = context;
        this.mDate = mDate;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.rv_my_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        holder.itemName.setText(mDate.get(position));
        holder.myItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDate.get(position).equals("修改密码")) {
                    context.startActivity(new Intent(context, ChangePasswordActivity.class));
                }else {
                    ToastUtil.showToast("暂未开放，静候佳音");
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDate.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView itemName;
        private final LinearLayout myItem;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            itemName = (TextView) itemView.findViewById(R.id.tv_tab_name);
            myItem = (LinearLayout) itemView.findViewById(R.id.ll_my_item);
        }
    }
}
